// 尝试从sessionStorage获取用户信息
const user = JSON.parse(sessionStorage.getItem('userInfo')) || {}

const User = {
  state: {
    acc_id: user.acc_id || '', // 用户id
    access_token: user.access_token || '', // 用户token
    uid: user.uid || '' // 用户uid
  },
  mutations: {
    SetUserInfo: (state, { acc_id, access_token, uid }) => {
      sessionStorage.setItem('userInfo', JSON.stringify({ acc_id, access_token, uid }))
      /* eslint-disable */
      state.acc_id = acc_id
      state.access_token = access_token
      state.uid = uid
    },
    resetUserInfo: state => {
      state.acc_id = ''
      state.access_token = ''
      state.uid = ''
    }
  }
}

export default User
